package knowall.client.questionCreation;

import java.util.Arrays;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.RichTextArea;

public class QuestionTextPopup extends PopupPanel {

	private static final Binder binder = GWT.create(Binder.class);
	
	@UiField RichTextArea richTextArea;
	
	Button button;
	List<String> words;

	interface Binder extends UiBinder<Widget, QuestionTextPopup> {
	}

	public QuestionTextPopup() {
		setWidget(binder.createAndBindUi(this));
	}
	
	public QuestionTextPopup(Button button, List<String> words) {
		setWidget(binder.createAndBindUi(this));
		this.button = button;
		this.words = words;
	}

	@UiHandler("cancelBtn")
	void onCancelBtnClick(ClickEvent event) {
		button.setEnabled(true);
		this.hide();
	}
	
	@UiHandler("okBtn")
	void onOkBtnClick(ClickEvent event) {
		button.setEnabled(true);
		this.hide();
		for(String s : Arrays.asList(richTextArea.getText().split(" "))) {
			words.add(s);
		}
	}
}
